
const Controller = require('../../core/Controller');
const TopClient = require('../../topClient').TopClient;
const query = require('../../core/db');


class couponController extends Controller {
  constructor() {
    super();
  }
  async getGoodsList(ctx) {
    let sql = 'select * from goods where 1=1';
    let values = [];
    ctx.response.body = await query(sql, values).then( results => { return results; });
  }
  async getAllGoodsList(ctx) {
    //let sql = 'select * from goods where 1=1';
    //let values = [];
    //ctx.response.body = await query(sql, values).then( results => { return results; });
    console.log('getAllGoodsList');
    var client = new TopClient({
      'appkey': '24543960',
      'appsecret': '1bfaf3acf176650779faf3bb465acc9d',
      'REST_URL': 'http://gw.api.taobao.com/router/rest',
      'session': '61029203eaea91df988f83029cb61979b67628eff92aaea3355153118'
    });
    console.log(client);
    ctx.response.body = 123;

    client.execute('taobao.items.onsale.get', {
      'fields':'num_iid,title,price',
      'q':'N97',
      'cid':'1512',
      'seller_cids':'11',
      'page_no':'10',
      'has_discount':'true',
      'has_showcase':'true',
      'order_by':'list_time:desc',
      'is_taobao':'true',
      'is_ex':'true',
      'page_size':'100',
      'start_modified':'2000-01-01 00:00:00',
      'end_modified':'2000-01-01 00:00:00',
      'is_cspu':'true',
      'is_combine':'true'
    }, function(error, response) {
      if (!error) console.log(response);
      else console.log(error);
    })
  }
}

module.exports = new couponController;
